package com.aj.http.request;

import java.io.File;
import java.util.HashMap;

import android.content.Context;
import android.util.Log;

import com.aj.http.AsynchronizationHttpRequest;
import com.aj.http.AsynchronizationHttpRequest.IHttpCallBack;

public class UploadPhotoRequest extends BaseRequset {
	private static final String TAG = UploadPhotoRequest.class.getName();

	public void excute(Context context, String smallWidth, String smallHeigth,
			String fileType, File file, IHttpCallBack httpCallBack) {
		excute(context, smallWidth, smallHeigth, fileType, file, httpCallBack,
				true);
	}

	public void excute(Context context, String smallWidth, String smallHeigth,
			String fileType, File file, IHttpCallBack httpCallBack,
			boolean isAsyn) {
		HashMap<String, String> paramsHashMap = new HashMap<String, String>();
		if (smallWidth != null && !smallWidth.trim().equals("")) {
			paramsHashMap.put("smallWidth", smallWidth);
		}
		if (smallHeigth != null && !smallHeigth.trim().equals("")) {
			paramsHashMap.put("smallHeigth", smallHeigth);
		}
		paramsHashMap.put("fileType", fileType);

		String tempString = getParams(SERVICE_UPDATE_USERINFO_STRING,
				paramsHashMap);
		Log.e(TAG, "tempString:" + tempString);
		// TODO加密
		AsynchronizationHttpRequest request = new AsynchronizationHttpRequest();
		if (isAsyn) {
			request.excuteFile(context, BASE_UPLOADFILE_URL_NOPAGE_STRING,
					tempString, file, httpCallBack);
		} else {
			request.excuteSynFile(context, BASE_UPLOADFILE_URL_NOPAGE_STRING,
					tempString, file, httpCallBack);
		}
	}

	public void excuteSync(Context context, String smallWidth,
			String smallHeigth, String fileType, File file,
			IHttpCallBack httpCallBack) {
		HashMap<String, String> paramsHashMap = new HashMap<String, String>();
		if (smallWidth != null && !smallWidth.trim().equals("")) {
			paramsHashMap.put("smallWidth", smallWidth);
		}
		if (smallHeigth != null && !smallHeigth.trim().equals("")) {
			paramsHashMap.put("smallHeigth", smallHeigth);
		}
		paramsHashMap.put("fileType", fileType);

		String tempString = getParams(SERVICE_UPDATE_USERINFO_STRING,
				paramsHashMap);
		Log.e(TAG, "tempString:" + tempString);
		// TODO加密
		AsynchronizationHttpRequest request = new AsynchronizationHttpRequest();
		request.excuteSynFile(context, BASE_UPLOADFILE_URL_NOPAGE_STRING,
				tempString, file, httpCallBack);
	}
}
